package com.ruoyi.common.enums;

import com.baomidou.mybatisplus.annotation.EnumValue;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonValue;
import com.ruoyi.common.annotation.EnumConverter;
import com.ruoyi.common.utils.StringUtils;
import lombok.AllArgsConstructor;
import lombok.Getter;
import org.springframework.core.convert.converter.Converter;

/**
 * 人员事件类型
 */
@Getter
@AllArgsConstructor
@JsonFormat(shape = JsonFormat.Shape.STRING)
public enum UserEventType {

    EVENT_QD("event_qd"),
    EVENT_TH("event_th"),
    EVENT_NJ("event_nj"),
    EVENT_JF("event_jf"),
    EVENT_RISK_JUDGE("event_risk_judge"),

    ;

    @EnumValue
    private final String userType;

    @JsonValue
    public String getUserType() {
        return userType;
    }

    @EnumConverter
    public static class InnerConverter implements Converter<String, UserEventType> {
        @Override
        public UserEventType convert(String source) {
            return getUserType(source);
        }

    }

    public static UserEventType getUserType(String str) {
        for (UserEventType value : values()) {
            if (StringUtils.contains(str, value.getUserType())) {
                return value;
            }
        }
        throw new RuntimeException("'UserBusinessType' not found By " + str);
    }

}
